package com.slwu.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.slwu.entity.Plot;
import com.slwu.mapper.PlotMapper;
import com.slwu.request.plot.PlotPageParam;
import com.slwu.service.IPlotService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wushaolin
 * @since 2025-10-29
 */
@Service
public class PlotServiceImpl extends ServiceImpl<PlotMapper, Plot> implements IPlotService {

    @Override
    public Page<Plot> page(PlotPageParam plotPageParam) {
        QueryWrapper<Plot> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(plotPageParam.getSearchKey())) {
            queryWrapper.lambda().like(Plot::getName, plotPageParam.getSearchKey());
        }
        if (ObjectUtil.isNotEmpty(plotPageParam.getVillage())) {
            queryWrapper.lambda().eq(Plot::getVillage, plotPageParam.getVillage());
        }
        return (Page<Plot>) this.page(plotPageParam.createPage(), queryWrapper);
    }
}
